package com.example.mymvvmdemo.models.agreement;

import android.content.Intent;

import com.example.mymvvmdemo.MyApplication;
import com.example.mymvvmdemo.R;
import com.example.mymvvmdemo.base.BaseLoadActivity;
import com.example.mymvvmdemo.constants.Constants;
import com.example.mymvvmdemo.databinding.ActivityAgreementBinding;
import com.example.mymvvmdemo.dialog.AgreementDialog;
import com.example.mymvvmdemo.dialog.LoadingAnimDialog;
import com.example.mymvvmdemo.models.login.LoginActivity;
import com.example.mymvvmdemo.utils.SpUtils;

public class AgreementActivity extends BaseLoadActivity<ActivityAgreementBinding> {

    private AgreementDialog agreementDialog;

    /*** 加载时候的Dialog */
    private LoadingAnimDialog loadingDialog;

    @Override
    protected void showDialog() {
        if (loadingDialog == null)
            loadingDialog = new LoadingAnimDialog(this, getResources().getString(R.string.load));
        if (!loadingDialog.isShowing()) loadingDialog.show(this);
    }

    @Override
    protected void dismissDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.close(this);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    public void initDialog() {
        super.initDialog();

        agreementDialog = new AgreementDialog(this);
        agreementDialog.setText(getString(R.string.agreement_context));
        agreementDialog.setListener(new AgreementDialog.PromptClickListener() {
            @Override
            public void onCancelClick() {
                finish();
            }

            @Override
            public void onConfirmClick() {

                SpUtils.getSpUtils(MyApplication.getInstance(), Constants.ACCOUNT_NAME)
                        .putValue(Constants.USER_PRIVATE, true);

                Intent intent = new Intent(AgreementActivity.this, LoginActivity.class);
                startActivity(intent);

            }
        });
        agreementDialog.show();

    }
}